<template>
  <div class="app-container customer-div" v-loading="supplierInfoLoading">
    <div>
      <div style="font-size:24px;font-weight: bold;margin-bottom:10px;">
        {{supplierForm.supplierName}}
        <span style="padding-left:20px">{{supplierForm.supplierGrade}}</span>
        <el-button v-if="supplierForm.supplierId&&supplierForm.isMy" type="primary" size="mini" @click="toAddupplier('edit',supplierForm.supplierId)">编辑</el-button>
      </div>
      <div style="font-size:12px;color:#888">
        <span>创建时间：{{supplierForm.createTime}}</span>
        <span style="padding-left:10px;">最近更新时间：{{supplierForm.updatedTime}}</span>
        <span style="padding-left:10px;">负责人：{{supplierForm.chargeUserNames}}</span>
      </div>
      <div>
        <el-button size="small" @click="showGL" type="text" v-if="supplierForm.supplierId&&supplierForm.isMy">增加关联公司</el-button>
      </div>
    </div>

    <div style="overflow: hidden;margin-bottom:20px;margin-top:20px;">
      <div style="float:left;min-width:140px;text-align: center;border:1px solid #eee;border-radius: 10px;padding:20px;">
          <div style="font-size:20px;font-weight:bold;margin-bottom:10px">{{supplierForm.purchaseNum}}</div>
          <div style="font-size:14px;color:#888;">采购订单总数</div>
      </div>
      <div style="float:left;min-width:140px;text-align: center;border:1px solid #eee;border-radius: 10px;padding:20px;margin-left:20px;">
          <div style="font-size:20px;font-weight:bold;margin-bottom:10px">{{supplierForm.purchaseAmount}}</div>
          <div style="font-size:14px;color:#888;">采购总额</div>
      </div>
      <div v-if="supplierForm.successNumStatistics">
        <div style="float:left;min-width:140px;text-align: center;border:1px solid #eee;border-radius: 10px;padding:20px;margin-left:20px;">
            <div style="font-size:20px;font-weight:bold;margin-bottom:10px">{{supplierForm.successNumStatistics.PA6?supplierForm.successNumStatistics.PA6:0}}</div>
            <div style="font-size:14px;color:#888;">PA6</div>
        </div>
        <div style="float:left;min-width:140px;text-align: center;border:1px solid #eee;border-radius: 10px;padding:20px;margin-left:20px;">
            <div style="font-size:20px;font-weight:bold;margin-bottom:10px">{{supplierForm.successNumStatistics.PA66?supplierForm.successNumStatistics.PA66:0}}</div>
            <div style="font-size:14px;color:#888;">PA66</div>
        </div>
        <div style="float:left;min-width:140px;text-align: center;border:1px solid #eee;border-radius: 10px;padding:20px;margin-left:20px;">
            <div style="font-size:20px;font-weight:bold;margin-bottom:10px">{{supplierForm.successNumStatistics.ABS?supplierForm.successNumStatistics.ABS:0}}</div>
            <div style="font-size:14px;color:#888;">ABS</div>
        </div>
        <div style="float:left;min-width:140px;text-align: center;border:1px solid #eee;border-radius: 10px;padding:20px;margin-left:20px;">
            <div style="font-size:20px;font-weight:bold;margin-bottom:10px">{{supplierForm.successNumStatistics.PC?supplierForm.successNumStatistics.PC:0}}</div>
            <div style="font-size:14px;color:#888;">PC</div>
        </div>
        <div style="float:left;min-width:140px;text-align: center;border:1px solid #eee;border-radius: 10px;padding:20px;margin-left:20px;">
            <div style="font-size:20px;font-weight:bold;margin-bottom:10px">{{supplierForm.successNumStatistics.other?supplierForm.successNumStatistics.other:0}}</div>
            <div style="font-size:14px;color:#888;">其它</div>
        </div>
      </div>
    </div>

      <el-tabs v-model="activeName">
          <el-tab-pane label="基本信息" name="1">
              <el-form :model="supplierForm" size="mini" label-width="180px"  ref="supplierForm" style="width:1000px">
                  <el-form-item label="供应商名称：">
                    {{supplierForm.supplierName}}
                  </el-form-item>
                  <el-form-item label="统一社会信用代码：">
                    {{supplierForm.businessCode}}
                  </el-form-item>
                  <el-form-item label="营业执照：" >
                    <el-image
                      style="width:350px;height:180px"
                      :src="supplierForm.businessLicense"
                      :preview-src-list="supplierForm.businessLicense?supplierForm.businessLicense.split(','):[]">
                      <div slot="error" class="image-slot">
                        <div style="width:350px;height:180px;text-align:center;line-height:180px;border:1px solid #eee;">
                          暂无图片
                        </div>
                      </div>
                    </el-image>
                  </el-form-item>
                  <el-form-item label="资料完善度：">
                    {{supplierForm.completeRate}}
                  </el-form-item>
                  <el-form-item label="准入状态：" >
                    {{supplierForm.supplierState|filterSupplierState}}
                  </el-form-item>
                  <el-form-item label="成立日期：" >
                    {{supplierForm.regDate}}
                  </el-form-item>
                  <el-form-item label="法人：">
                    {{supplierForm.legalPerson}}
                  </el-form-item>
                  <el-form-item label="注册资金：">
                    {{supplierForm.regMoney}}
                  </el-form-item>
                  <el-form-item label="实缴资金：">
                    {{supplierForm.actualMoney}}
                  </el-form-item>
                  <el-form-item label="所在地区：">
                      {{supplierForm.address}}
                  </el-form-item>
                  <el-form-item label="注册地址：">
                      {{supplierForm.addressDetail}}
                  </el-form-item>
                   <el-form-item label="实际地址：">
                      {{supplierForm.actualAddress}}
                  </el-form-item>
              </el-form>
          </el-tab-pane>

          <el-tab-pane label="组织人员" name="2">
             <div style="font-size:16px;font-weight: bold">
                <el-button v-if="supplierForm.isMy" type="primary" size="small" @click="showAddContact('add',supplierForm.supplierId)">
                  新增人员
                </el-button>
              </div>
              <div class="table-container">
                  <el-table
                    :header-cell-style="{'text-align':'center'}"
                    :data="supplierContactList"
                    border
                    style="width: 100%; margin-top: 20px">
                    <el-table-column
                      label="联系人"
                      align="center"
                      prop="contactName">
                    </el-table-column>
                    <el-table-column
                      label="手机号"
                      align="center"
                      prop="contactMobile">
                    </el-table-column>
                    <el-table-column
                      label="职务"
                      align="center"
                      prop="contactDuty">
                    </el-table-column>
                    <el-table-column
                      label="是否为主联系人"
                      align="center">
                      <template slot-scope="{row}">
                        {{row.isMainContact==1?'是':'否'}}
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="是否有采购决定权"
                      align="center">
                      <template slot-scope="{row}">
                        {{row.isBuyPermission==1?'是':'否'}}
                      </template>
                    </el-table-column>
                    <el-table-column
                      label="产品线"
                      align="center"
                      prop="goodsLineName">
                    </el-table-column>
                    <el-table-column
                      v-if="supplierForm.isMy"
                      label="操作"
                      align="center">
                      <template slot-scope="scope">
                          <el-button
                            type="text"
                            size="mini"
                            @click="showAddContact('edit',scope.row)">编辑
                          </el-button>
                          <el-button
                            type="text"
                            size="mini"
                            @click="delContact(scope.row)">删除
                          </el-button>
                      </template>
                    </el-table-column>
                  </el-table>
              </div>
              <div class="pagination-container">
                <el-pagination
                  background
                  @size-change="handleSizeContact"
                  @current-change="handleCurrentContact"
                  layout="total, sizes,prev, pager, next,jumper"
                  :current-page.sync="listQueryContact.pageNum"
                  :page-size="listQueryContact.pageSize"
                  :page-sizes="[10,15,20]"
                  :total="supplierContactCount">
                </el-pagination>
              </div>
          </el-tab-pane>

          <el-tab-pane label="供应商等级" name="3">
             <el-form :model="supplierForm" size="mini" label-width="180px"  ref="supplierForm" style="width:1000px">
                  <el-form-item label="是否意向获得代理授权：">
                    {{supplierForm.isIntentionAgent==1?'是':'否'}}
                  </el-form-item>
                  <el-form-item label="供应商类型：">
                    {{supplierForm.supplierType}}
                  </el-form-item>
                  <el-form-item label="供应商性质：" >
                    {{supplierForm.supplierQuantity}}
                  </el-form-item>
                  <el-form-item label="信用度：" >
                    {{supplierForm.supplierCredit}}
                  </el-form-item>
                  <el-form-item label="出货量&占有率：">
                    {{supplierForm.outQuantity}}
                  </el-form-item>
                  <el-form-item label="跟进等级：">
                    {{supplierForm.supplierLevel}}
                  </el-form-item>
                  <el-form-item label="预付款额度：">
                    {{supplierForm.prePayAmount}}
                  </el-form-item>
                 <el-form-item label="投产日期：">
                   {{supplierForm.productionDate === '0' ? '无投产日期' : supplierForm.productionDate ? supplierForm.productionDate :  ''}}
                 </el-form-item>
             </el-form>
          </el-tab-pane>

          <el-tab-pane label="业务经营" name="4">
            <div style="font-size:16px;font-weight: bold">

              <div style="font-size:12px;margin-bottom:10px;font-weight: 500;padding:8px 16px;background: #f3fcec;color:#606266">
                <span>装置工艺:{{supplierForm.equipmentProcess}}</span>
                <span style="padding-left:50px;">原材料配置：</span><el-input style="width:150px"  size="mini" v-model="materialConfig"></el-input>
                <el-button type="primary" style="display: inline-block;margin-left:10px" size="mini" @click="addMaterialConfigFn" :disabled="materialConfig == ''">新增</el-button>
                <el-button  style="display: inline-block" size="mini" @click="showMaterialConfig">历史记录</el-button>
              </div>

              <el-button  size="small" @click="showAddGoods('add',supplierForm.supplierId)" type="primary">
                新增生产信息
              </el-button>

            </div>
            <div class="table-container">
              <el-table
                :header-cell-style="{'text-align':'center'}"
                :data="supplierGoodsList"
                border
                style="width: 100%; margin-top: 20px">
                <el-table-column
                  label="产品线"
                  align="center"
                  prop="goodsLineName">
                </el-table-column>
                <el-table-column
                  label="牌号"
                  align="center"
                  prop="goodsSn">
                </el-table-column>
                <el-table-column
                  label="产能(吨/每月)"
                  align="center"
                  prop="productionQuantity">
                </el-table-column>
                <el-table-column
                  label="库存(吨/月)"
                  align="center"
                  prop="supplierStock">
                </el-table-column>
                <el-table-column
                  label="产业链"
                  align="center"
                  prop="industrialChain">
                </el-table-column>
                <el-table-column
                  label="对标产品"
                  align="center"
                  prop="benchmarkingProduct">
                </el-table-column>
                <el-table-column
                  label="对标工厂"
                  align="center"
                  prop="benchmarkingFactory">
                </el-table-column>
                <el-table-column
                  label="销售模式"
                  align="center"
                  prop="saleModel">
                </el-table-column>
                <el-table-column
                  label="投产日期"
                  align="center"
                  prop="productionDate">
                  <template slot-scope="scope">
                      {{scope.row.productionDate === 0 ? '无投产日期' : scope.row.productionDate}}
                  </template>
                </el-table-column>
                <el-table-column
                  label="负责人"
                  align="center"
                  prop="purchaseUserName">
                </el-table-column>
                <el-table-column
                  label="操作"
                  align="center">
                  <template slot-scope="scope">
                    <el-button
                      type="text"
                      size="mini"
                      @click="showAddGoods('edit',scope.row)">编辑
                    </el-button>
                    <!-- <el-button
                      type="text"
                      size="mini"
                      @click="delGoods(scope.row)">删除
                    </el-button> -->
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div class="pagination-container">
              <el-pagination
                background
                @size-change="handleSizeGoods"
                @current-change="handleCurrentGoods"
                layout="total, sizes,prev, pager, next,jumper"
                :current-page.sync="listQueryGoods.pageNum"
                :page-size="listQueryGoods.pageSize"
                :page-sizes="[10,15,20]"
                :total="supplierGoodsCount">
              </el-pagination>
            </div>
          </el-tab-pane>

          <el-tab-pane label="采购合同" name="5">
              <div class="table-container">
                  <el-table
                          :header-cell-style="{'text-align':'center'}"
                          v-loading="listLoading3"
                          :data="list3"
                          border
                          style="width: 100%; margin-top: 20px">
                      <el-table-column  label="订单单号" >
                          <template slot-scope="scope">
                              <el-link @click="toInfo(scope.row)" type="primary">
                                  {{scope.row.orderSn}}
                              </el-link>

                          </template>
                      </el-table-column>
                      <el-table-column
                              label="采购日期"
                              align="center">
                          <template slot-scope="scope">
                              {{scope.row.createTime}}
                          </template>
                      </el-table-column>
                      <el-table-column
                              label="合同公司"
                              align="center">
                          <template slot-scope="scope">
                              {{scope.row.fromCompany}}
                          </template>
                      </el-table-column>
                      <el-table-column
                              label="采购数量"
                              align="center">
                          <template slot-scope="scope">
                              {{scope.row.goodsNum}}
                          </template>
                      </el-table-column>
                      <el-table-column
                              label="采购金额"
                              align="center">
                          <template slot-scope="scope">
                              {{scope.row.goodsAmount}}
                          </template>
                      </el-table-column>
                      <el-table-column
                              label="交货日期"
                              align="center">
                          <template slot-scope="scope">
                              {{scope.row.sendDate}}
                          </template>
                      </el-table-column>
                      <el-table-column
                              label="交货方式">
                          <template slot-scope="scope">
                              {{scope.row.sendType}}
                          </template>
                      </el-table-column>
                      <el-table-column
                              label="摘要">
                          <template slot-scope="scope">
                              {{scope.row.remark}}
                          </template>
                      </el-table-column>
                      <el-table-column
                              label="业务员"
                              align="center">
                          <template slot-scope="scope">
                              {{scope.row.userRealName}}
                          </template>
                      </el-table-column>
                  </el-table>
              </div>
              <div class="pagination-container">
                  <el-pagination
                          background
                          @size-change="handleSizeChange3"
                          @current-change="handleCurrentChange3"
                          layout="total, sizes,prev, pager, next,jumper"
                          :current-page.sync="listQuery3.pageNum"
                          :page-size="listQuery3.pageSize"
                          :page-sizes="[10,15,20]"
                          :total="count3">
                  </el-pagination>
              </div>
          </el-tab-pane>

          <el-tab-pane label="跟进记录" name="6">
              <div style="font-size:16px;font-weight: bold">
                  <el-button v-if="supplierForm.isMy" size="small" @click="showSupplierGj('add',supplierForm)" type="primary">
                    新增跟进
                  </el-button>
              </div>
              <div class="table-container">
                  <el-table
                    v-loading="trackingLoading"
                    :data="trackingList"
                    border
                    style="width: 100%; margin-top: 20px">
                      <el-table-column
                        prop="contactName"
                        label="联系人姓名"
                        align="center"
                        width="100">
                      </el-table-column>
                      <el-table-column
                        prop="supplierLevel"
                        label="跟进等级"
                        align="center"
                        width="100">
                      </el-table-column>
                      <el-table-column
                        prop="followUpValue"
                        label="跟进方式"
                        align="center"
                        width="100">
                      </el-table-column>
                      <el-table-column
                        prop="trackingMethodValue"
                        label="沟通方式"
                        align="center"
                        width="100">
                      </el-table-column>
                      <el-table-column
                        prop="trackingPurposeValue"
                        label="跟进目的"
                        align="center"
                        width="100">
                      </el-table-column>
                      <el-table-column
                        prop="trackingContent"
                        label="跟进内容"
                        align="left"
                        width="300">
                      </el-table-column>
                      <el-table-column
                        prop="trackingPics"
                        label="附件"
                        align="center"
                        width="250">
                        <template slot-scope="{row}">
                          <div v-if="row.trackingPics.length>0">
                          <div v-for="(item,index) in row.trackingPics" :key="index" :class="{imgStyle:checkFileType(item)=='image'}">
                            <!-- 音频 -->
                            <div v-if="checkFileType(item)=='audio'">
                              <audio controls style="width: 220px; height: 30px">
                                <source :src="item" type="audio/mpeg" />
                                <source :src="item" type="audio/ogg" />
                                <source :src="item" type="audio/mp3" />
                                您的浏览器不支持该音频格式。
                              </audio>
                            </div>
                            <!-- 图片 -->
                            <div v-else-if="checkFileType(item)=='image'" style="width: 40px;margin-right:10px">
                              <el-image
                                style="width: 40px; height: 40px;"
                                :src="item"
                                :preview-src-list="Array(item)">
                              </el-image>
                            </div>
                            <div v-else>
                              <div>{{ item }}</div>
                            </div>
                          </div>
                        </div>
                        </template>
                      </el-table-column>
                      <el-table-column
                        prop="trackingTime"
                        label="跟进日期"
                        width="150"
                        align="center">
                      </el-table-column>

                      <el-table-column
                        prop="trackingUser"
                        label="跟进人"
                        width="100"
                        align="center">
                      </el-table-column>
                      <el-table-column
                        prop="isInvalid"
                        label="目的是否完成"
                        width="100"
                        align="center">
                        <template slot-scope="{row}">
                          <div>{{ row.isInvalid==1?'是':'否' }}</div>
                        </template>
                      </el-table-column>
                      <el-table-column
                        prop="nextTrackingTime"
                        label="下次跟进时间"
                        width="150"
                        align="center">
                      </el-table-column>
                      <el-table-column
                        fixed="right"
                        width="150"
                        label="操作"
                        align="center">
                        <template slot-scope="scope">
                            <el-button
                              v-if="userId==scope.row.trackingUserId"
                              type="text"
                              size="mini"
                              @click="showSupplierGj('edit',scope.row)">编辑
                            </el-button>
                            <el-button
                              v-if="userId==scope.row.trackingUserId"
                              type="text"
                              size="mini"
                              @click="delTracking(scope.row)">删除
                            </el-button>
                        </template>
                      </el-table-column>
                  </el-table>
              </div>
              <div class="pagination-container">
                  <el-pagination
                          background
                          @size-change="handleSizeChangeTracking"
                          @current-change="handleCurrentChangeTracking"
                          layout="total, sizes,prev, pager, next,jumper"
                          :current-page.sync="trackingParams.pageNum"
                          :page-size="trackingParams.pageSize"
                          :page-sizes="[10,15,20]"
                          :total="trackingCount">
                  </el-pagination>
              </div>
          </el-tab-pane>

          <el-tab-pane label="操作记录" name="7">
              <div class="table-container">
                  <el-table
                          v-loading="logLoading"
                          :data="logList"
                          border
                          style="width: 100%; margin-top: 20px">
                      <el-table-column
                              width="150"
                              prop="operateTime"
                              label="操作时间"
                              align="center">
                      </el-table-column>
                      <el-table-column
                              width="100"
                              prop="operateUserName"
                              label="操作人"
                              align="center">
                      </el-table-column>
                      <el-table-column
                              prop="operateContent"
                              label="描述">
                      </el-table-column>
                  </el-table>
              </div>
              <div class="pagination-container">
                  <el-pagination
                          background
                          @size-change="handleSizeChangelog"
                          @current-change="handleCurrentChangelog"
                          layout="total, sizes,prev, pager, next,jumper"
                          :current-page.sync="logParams.pageNum"
                          :page-size="logParams.pageSize"
                          :page-sizes="[10,15,20]"
                          :total="logCount">
                  </el-pagination>
              </div>
          </el-tab-pane>
      </el-tabs>

      <!--增加关联公司-->
      <el-dialog
          :close-on-click-modal="false"
          :visible.sync="dialogVisible8"
          width="400px">
          <div style="max-height: 500px;overflow: auto">
              <el-form :inline="true" size="mini" label-width="120px" ref="GLForm" :model="GLForm">
                  <el-form-item label="供应商名称：">
                      <el-autocomplete
                              clearable
                              class="inline-input"
                              value-key="supplierName"
                              :fetch-suggestions="querySearch"
                              v-model="GLForm.gLSupplierName"
                              placeholder="请输入内容"
                              @select="handleSelectCustomerName"
                              :trigger-on-focus="false"
                      ></el-autocomplete>
                  </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer" style="text-align: right">
                  <el-button @click="handleClose8" size="small">取 消</el-button>
                  <el-button type="primary" @click="handleConfirm8" :loading="btnLoading9" size="small">确 定</el-button>
              </div>
          </div>
      </el-dialog>

      <!-- 组织人员 -->
      <addSupplierContact ref="addSupplierContact" @update="getSupplierContactList"></addSupplierContact>
      <!-- 业务经营 -->
      <addSupplierGoods ref="addSupplierGoods" @update="getSupplierGoodsList"></addSupplierGoods>
      <!-- 新增跟进 -->
      <addSupplierGj ref="addSupplierGj" @update="getTrackingListData"></addSupplierGj>

    <el-dialog
      :visible.sync="materialConfigShow"
      width="400px">
      <div style="max-height: 500px;overflow: auto;padding-top: 2px">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in supplierForm.materialConfigList"
            :key="index">
                         <span>
                             <span style="padding-right:10px;">{{activity.time}}</span>
                             {{activity.operator}}：{{activity.title}}
                         </span>

          </el-timeline-item>
        </el-timeline>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  commonSupplierContactList,
  getSupplierInfo,
  supplierContactList,
  supplierGoodsList,
  supplierContactDel,
  supplierGoodsDel
} from '@/api/company'
import {
  purchaseOrderGoodsList,
  getQiniuToken,
  supplierList,
  supplierTrackingList,
  supplierAddTracking,
  supplierTrackingType,
  supplierDelTracking,
  delRelationSupplier,
  addRelationSupplier,
  supplierlogList,
  addMaterialConfig
} from '@/api/partner'
import { formatDate } from '@/utils/date';
import { validatePhone } from '@/utils/validate';
import store from '@/store';
import { mapGetters } from 'vuex';
import addSupplierContact from './components/addSupplierContact.vue';
import addSupplierGoods from './components/addSupplierGoods.vue';
import addSupplierGj from './components/addSupplierGj.vue';
const defaultTrackingForm = {
  supplierId: '',
  customerName: '',
  contactId: '',
  followUpId: '',
  trackingContent: '',
  trackingTime: '',
  trackingPics: [],
  trackingRemark: '',
  nextTrackingTime: '',
  trackingId: 0,
};
export default {
  name: "supplierInfo",
  data() {
    return {
      supplierInfoLoading:false,
      roles: store.getters.roles ? store.getters.roles : [],
      supplierForm: {},
      activeName: '1',
      listQuery3: {
        pageNum: 1,
        pageSize: 10,
        supplierId:this.$route.query.id,
      },
      listLoading3: false,
      count3: 0,
      list3: [],
      uploadToken: {
        token: '',
      },
      imgDomain: '',
      dialogVisible8: false,
      GLForm: {
        gLSupplierId: '',
        gLSupplierName: '',
      },
      btnLoading9: false,
      trackingParams: {
        supplierId: this.$route.query.id,
        type:'self',
        pageNum: 1,
        pageSize: 10,
      },
      trackingList: [],
      trackingCount: 0,
      trackingLoading: false,
      trackingForm: JSON.parse(JSON.stringify(defaultTrackingForm)),
      rules5: {
        contactId: [{ required: true, message: '请选择联系人', trigger: 'change' },],
        followUpId: [{ required: true, message: '请选择跟时方式', trigger: 'change' },],
        trackingContent: [{ required: true, message: '请填写跟进内容', trigger: 'blur' },],
        trackingTime: [{ required: true, message: '请选择跟进日期', trigger: 'change' },],
      },
      customerTrackingList: [],
      contactList: [],
      logParams: {
        supplierId:this.$route.query.id,
        pageNum: 1,
        pageSize: 10,
      },
      logList: [],
      logCount: 0,
      logLoading: false,
      listQueryContact: {
        supplierId:this.$route.query.id,
        pageNum: 1,
        pageSize: 10,
      },
      supplierContactList: [],
      supplierContactCount: 0,
      listQueryGoods: {
        supplierId:this.$route.query.id,
        pageNum: 1,
        pageSize: 10,
      },
      supplierGoodsList: [],
      supplierGoodsCount: 0,
      materialConfig:'',
      materialConfigShow:false
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  components: {
    addSupplierContact,
    addSupplierGoods,
    addSupplierGj
  },
  created() {
    this.showCon();//供应商详情
    this.getSupplierContactList();//组织人员
    this.getSupplierGoodsList();//业务经营
    this.getTrackingListData();//跟进记录
    this.getList3();//采购合同
    this.getUploadToken();
    this.getListDatalog();//操作记录
  },
  filters: {
    formatTime(time) {
      let date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd')
    },
    filterSupplierState(val) {
      if (val == 0) {
        return '待准入'
      } else if (val == 10) {
        return '审核中'
      } else if (val == 20) {
        return '已准入'
      } else if (val == 30) {
        return '不予以准入'
      }
    }
  },
  methods: {
    showMaterialConfig(){
      this.materialConfigShow = true
    },
    addMaterialConfigFn(){
      addMaterialConfig({supplierId:this.$route.query.id,materialConfig:this.materialConfig}).then((res)=>{
         this.$message('操作成功')
         this.showCon()
      })
    },
     // 判断文件类型
    checkFileType(fileName) {
      if (fileName.match(/\.(jpg|jpeg|png|gif|webp)/)) {
        return "image";
      } else if (fileName.match(/\.(doc|docx)/)) {
        return "word";
      } else if (fileName.match(/\.(wav|mp3|aac|ogg|wma)/)) {
        return "audio";
      } else {
        return "unknown";
      }
    },
    // 新增生产信息
    showAddGoods(type, item) {
      console.log(this.name,this.mobile,this.userId);
      if (type == 'add') {
        this.$refs.addSupplierGoods.showPop(type,item)
      } else if (type == 'edit') {
        this.$refs.addSupplierGoods.showPop(type,item)
      }
    },

    // 新增编辑组织人员
    showAddContact(type, item) {
      if (type == 'add') {
        this.$refs.addSupplierContact.showPop(type,item)
      } else if (type == 'edit') {
        this.$refs.addSupplierContact.showPop(type,item)
      }
    },
    //删除组织人员
    delContact(item) {
      this.$confirm('确定删除该组织人员?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        supplierContactDel({ contactId: item.contactId }).then(() => {
          this.getSupplierContactList();
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 获取业务经营列表
    getSupplierGoodsList() {
      supplierGoodsList(this.listQueryGoods).then((res) => {
        this.supplierGoodsList = res.list;
        this.supplierGoodsCount = res.count;
      })
    },
    handleSizeGoods(val) {
      this.listQueryGoods.pageNum = 1;
      this.listQueryGoods.pageSize = val;
      this.getSupplierGoodsList();
    },
    handleCurrentGoods(val) {
      this.listQueryGoods.pageNum = val;
      this.getSupplierGoodsList();
    },
    // 获取供应商组织人员列表
    getSupplierContactList() {
      supplierContactList(this.listQueryContact).then((res) => {
        this.supplierContactList = res.list;
        this.supplierContactCount = res.count;
      })
    },
    handleSizeContact(val) {
      this.listQueryContact.pageNum = 1;
      this.listQueryContact.pageSize = val;
      this.getSupplierContactList();
    },
    handleCurrentContact(val) {
      this.listQueryContact.pageNum = val;
      this.getSupplierContactList();
    },
    // 编辑供应商
    toAddupplier(type, id) {
      this.$router.push({ name: 'addSupplier', query: { type: type, id: id } })
    },
    //获取操作记录列表
    getListDatalog() {
      this.logLoading = true;
      let data = JSON.parse(JSON.stringify(this.logParams));
      supplierlogList(data).then((res) => {
        this.logList = res.list;
        this.logCount = res.count;
        this.logLoading = false;
      }).catch(() => {
        this.logLoading = false;
      })
    },

    handleSizeChangelog(val) {
      this.logParams.pageNum = 1;
      this.logParams.pageSize = val;
      this.getListDatalog();
    },
    handleCurrentChangelog(val) {
      this.logParams.pageNum = val;
      this.getListDatalog();
    },

    //去采购合同详情页
    toInfo(item) {
      let routeData = this.$router.resolve({ name: 'purchaseContractDetail', query: { id: item.orderId } });
      window.open(routeData.href);
    },
    //删除跟进
    delTracking(item) {
      this.$confirm('确定删除跟进记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        supplierDelTracking({ trackingId: item.trackingId }).then(() => {
          this.getTrackingListData();
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //上传图片
    handleAvatarSuccess2(res) {
      this.trackingForm.trackingPics.push(this.imgDomain + res.key)
    },

    //删除图片
    delImg2(index) {
      this.trackingForm.trackingPics.splice(index, 1)
    },

    //显示新增/编辑跟进
    showSupplierGj(type,item) {
      if (type == 'add') {
        this.$refs.addSupplierGj.showPop(type,item)
      } else if (type == 'edit') {
        this.$refs.addSupplierGj.showPop(type,item)
      }
    },
    //获取跟进记录
    getTrackingListData() {
      this.trackingLoading = true;
      supplierTrackingList(this.trackingParams).then((res) => {
        this.trackingList = res.list;
        this.trackingCount = res.count;
        this.trackingLoading = false;
      }).catch(() => {
        this.trackingLoading = false;
      })
    },
    handleSizeChangeTracking(val) {
      this.trackingParams.pageNum = 1;
      this.trackingParams.pageSize = val;
      this.getTrackingListData();
    },
    handleCurrentChangeTracking(val) {
      this.trackingParams.pageNum = val;
      this.getTrackingListData();
    },

    //供应商名称输入匹配
    querySearch(queryString, cb) {
      supplierList({ supplierName: queryString }).then((res) => {
        cb(res);
      })
    },

    //选择供应商名称
    handleSelectCustomerName(item) {
      this.GLForm.gLSupplierId = item.supplierId;
      this.GLForm.gLSupplierName = item.supplierName;
    },

    //删除关联公司
    delGlcustomer(item) {
      this.$confirm('确认删除此条记录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        delRelationSupplier({ supplierId: this.$route.query.id, rSupplierId: item.supplierId }).then(() => {
          this.showCon();
        }).catch(() => {
        })
      }).catch(() => {

      });
    },
    //显示关联公司
    showGL() {
      this.dialogVisible8 = true;
    },
    //关闭关联公司弹窗
    handleClose8() {
      this.dialogVisible8 = false;
      this.GLForm.gLSupplierId = '';
      this.GLForm.gLSupplierName = '';
    },

    //提交关联公司
    handleConfirm8() {
      this.$refs.GLForm.validate((valid) => {
        if (valid) {
          this.btnLoading8 = true;
          addRelationSupplier({ supplierId: this.$route.query.id, rSupplierId: this.GLForm.gLSupplierId }).then(() => {
            this.btnLoading8 = false;
            this.handleClose8();
            this.showCon();
          }).catch(() => {
            this.btnLoading8 = false;
          })
        }
      })
    },
    //获取七牛TOKEN
    getUploadToken() {
      getQiniuToken().then((res) => {
        this.uploadToken.token = res.token;
        this.imgDomain = res.domain
      })
    },

    //获取采购订单列表
    getList3() {
      this.listLoading3 = true;
      purchaseOrderGoodsList(this.listQuery3).then(response => {
        this.list3 = response.list;
        this.count3 = response.count;
        this.listLoading3 = false;
      }).catch(() => {
        this.listLoading3 = false;
      });
    },
    handleSizeChange3(val) {
      this.listQuery3.pageNum = 1;
      this.listQuery3.pageSize = val;
      this.getList3();
    },
    handleCurrentChange3(val) {
      this.listQuery3.pageNum = val;
      this.getList3();
    },

    //返回
    toBalck() {
      this.$router.go(-1)
    },

    //显示新建编辑客户详情
    showCon() {
      this.supplierInfoLoading = true;
      getSupplierInfo({ supplierId: this.$route.query.id }).then(res => {
        this.supplierInfoLoading = false;
        this.supplierForm = res;
        this.materialConfig = res.materialConfig
      }).catch(() => {
        this.supplierInfoLoading = false;
      })
    },

  },
};
</script>

<style scoped lang="scss">
.avatar-uploader{
  margin-bottom:10px;
  width:80px;
  height:80px;
  border:1px solid #DCDFE6;
  text-align: center;
  line-height: 80px;
}
.imgStyle{
  float: left;
}
</style>
<style scoped lang="scss">

</style>
